home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / Menu Fixer 1.0 Source / Menu fixer ƒ / Fix code ƒ / fix.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-15  |  3.4 KB  |  131 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        fix.c
  4.  
  5. Purpose:    This module handles program initialization and the main
  6.             procedure for checking menu IDs.
  7.  
  8.  
  9. Menu Fixer -=- synchronize menu IDs and menu resource IDs
  10. Copyright (C) 1993 Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "fix.h"
  30. #include "fix meat.h"
  31. #include "fix generic open.h"
  32. #include "fix files.h"
  33. #include "fix structs.h"
  34. #include "msg environment.h"
  35. #include "msg graphics.h"
  36. #include "msg menus.h"
  37. #include "msg dialogs.h"
  38.  
  39. FSSpec            editFile;
  40.  
  41. extern    unsigned long ts:0x09d2;
  42.  
  43. void InitProgram(void)
  44. {
  45.     int            i,j,k;
  46.     AppFile        myFile;
  47.     
  48.     editFile.name[0]=0x00;
  49.     
  50.     CountAppFiles(&i, &j);
  51.     if ((j>0) && (i==0))
  52.     {
  53.         GetAppFiles(1, &myFile);
  54.         MyMakeFSSpec(myFile.vRefNum, 0, myFile.fName, &editFile);
  55.         GenericOpen(&editFile);
  56.     }
  57. }
  58.  
  59. void OpenTheFile(void)
  60. {
  61.     int                thisRefNum;
  62.     int                oldResFile;
  63.     int                numTotalMenus, numFixed, numIgnored;
  64.     Str255            tempStr1, tempStr2, tempStr3;
  65.     int                resultCode;
  66.     unsigned long    oldTopMapHndl;
  67.     Boolean            resFileAlreadyOpen;
  68.     int                theResError;
  69.     
  70.     if (editFile.name[0]==0x00)
  71.     {
  72.         GetSourceFile(&editFile, FALSE);
  73.         if (editFile.name[0]==0x00)
  74.             return;
  75.     }
  76.     
  77.     oldResFile=CurResFile();
  78.     oldTopMapHndl=(unsigned long)TopMapHndl;
  79.     thisRefNum=HOpenResFile(editFile.vRefNum, editFile.parID, editFile.name, fsRdWrPerm);
  80.     theResError=ResError();
  81.     resFileAlreadyOpen=(oldTopMapHndl==(unsigned long)TopMapHndl);
  82.     
  83.     if (theResError!=0)
  84.     {
  85.         NumToString(theResError, tempStr1);
  86.         switch (theResError)
  87.         {
  88.             case -39:
  89.                 ParamText(editFile.name, "\pthis file does not have a resource fork",
  90.                     tempStr1,"\p");
  91.                 break;
  92.             case -49:
  93.                 ParamText(editFile.name, "\pthis file is already open in another application",
  94.                     tempStr1,"\p");
  95.                 break;
  96.             default:
  97.                 ParamText(editFile.name, "\pan unexpected error occurred",tempStr1,
  98.                     "\p");
  99.                 break;
  100.         }
  101.         PositionDialog('ALRT', resErrorAlert);
  102.         StopAlert(resErrorAlert, 0L);
  103.     }
  104.     else
  105.     {
  106.         UseResFile(thisRefNum);
  107.         gNumTotalMenus=gNumFixedMenus=gNumBadMenus=0;
  108.         resultCode=MenuFixer(editFile, thisRefNum, resFileAlreadyOpen);
  109.         UseResFile(oldResFile);
  110.         if (!resFileAlreadyOpen)
  111.             CloseResFile(thisRefNum);
  112.         FlushVol(0L, editFile.vRefNum);
  113.         if (resultCode!=allsWell)
  114.         {
  115.             ParamText(editFile.name, "\p", "\p", "\p");
  116.             PositionDialog('ALRT', noMenusAlert);
  117.             StopAlert(noMenusAlert, 0L);
  118.         }
  119.         else
  120.         {
  121.             NumToString(gNumTotalMenus, tempStr1);
  122.             NumToString(gNumBadMenus, tempStr2);
  123.             NumToString(gNumFixedMenus, tempStr3);
  124.             ParamText(editFile.name, tempStr1, tempStr2, tempStr3);
  125.             PositionDialog('ALRT', resultsAlert);
  126.             Alert(resultsAlert, 0L);
  127.         }
  128.     }
  129.     editFile.name[0]=0x00;
  130. }
  131.